package com.guide.utils;

import org.json.JSONException;
import org.springframework.stereotype.Component;

import com.qiniu.api.auth.AuthException;
import com.qiniu.api.auth.digest.Mac;
import com.qiniu.api.rs.PutPolicy;
@Component
public class QiNiuUtils {

	    
	
	    
	    public static String getUpToken() {
	    	String accessKey = PropertiesUtil.getPropertySys("AccessKey");
	    	String secretKey = PropertiesUtil.getPropertySys("SecretKey");
	    	Mac mac = new Mac(accessKey, secretKey);
			String bucketName = PropertiesUtil.getPropertySys("bucketName");
			PutPolicy putPolicy = new PutPolicy(bucketName);
			String uptoken = null;
		    try {
				 uptoken = putPolicy.token(mac);
			} catch (AuthException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		    return uptoken;
	    }
}
